import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;

public class Loader {
	protected String table[][];
	protected String header [];
	
	public Loader (String fileName) throws FileNotFoundException, IOException 
	{
		File F = new File (fileName);
		
		if (!F.exists()) throw new FileNotFoundException ();
		FileInputStream fis = new FileInputStream(F);
		BufferedReader br = new BufferedReader (new InputStreamReader (fis));
		String line=br.readLine();
		int size=Integer.valueOf(line);
		table = new String [size][size];
		header = new String[size];
	  
		for(int i=0;i<size;i++)
		{
		   	for (int j = 0; j < size; j ++)
		   	{
		   		table[i][j] = "-1";
		   	}
	   }
	   
		for (int j = 0; j < size; j ++)header[j] = j+"";
	   //for(Vector<String>);
		while (br.ready())
		{
			line = br.readLine();
			String ss[] = line.split("\\ ");
			int from=Integer.valueOf(ss[0]);
			int to=Integer.valueOf(ss[1]);
			int weight=Integer.valueOf(ss[2]);
			from --; 
			to --;
			table[from][to] = weight+"";	
			table[to][from] = weight+"";	
		}

/*		for(int j=0;j<size;j++)
		{
			System.out.print (header[j]+" ");
		}
		System.out.println ();
		for(int i=0;i<size;i++)
		{
			for(int j=0;j<size;j++)
			{
				System.out.print (table[i][j]+" ");
			}
			System.out.println ();
		}
		
*/		
	}
	
	public DefaultTableModel getTable ()
	{
		return new DefaultTableModel (table, header);
	}

}
